<?php

namespace Cyv\Laravel;
use Illuminate\Foundation\Http\FormRequest;

class BaseRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function commonRules(): array
    {
        return [];
    }

    public function rules(): array
    {
        $operation = $this->getOperation();
        $method    = $operation . 'Rules';
        $rules     = ($operation && method_exists($this, $method)) ? $this->$method() : [];
        return array_merge($rules, $this->commonRules());
    }

    /**
     * @return string|null
     */
    protected function getOperation(): ?string
    {
        return explode('@', $this->route()->getActionName())[1];
    }
}